home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / Egypt.lzh / Egypt / sources / Egypt.c next >
C/C++ Source or Header  |  1993-02-15  |  20KB  |  1,205 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3.  
  4. #include "gfx.h"
  5.  
  6. /**************/
  7. /* prototypes */
  8. /**************/
  9.  
  10. void PrintAt(__D0 SHORT, __D1 SHORT, __A0 char *);
  11. void PutField(__A0 struct Player *, __D0 SHORT, __D1 SHORT);
  12.  
  13. SHORT SelectOption();
  14. BOOL About();
  15. BOOL Game();
  16. void ChangePos(__A0 struct Player *);
  17. BOOL DoPlayer(__A0 struct Player *, __D0 UBYTE);
  18. void CreateWorld();
  19. int main();
  20.  
  21. /***********/
  22. /* globals */
  23. /***********/
  24.  
  25. /* font def */
  26.  
  27. struct TextAttr fontdef =
  28.     {
  29.     "topaz.font",
  30.     8,
  31.     FS_NORMAL,
  32.     FPF_ROMFONT
  33.     };
  34.  
  35. /* Option Gadget Render1 */
  36.  
  37. SHORT OGadget_Render1XYa[] =
  38.     {
  39.     0, 0,
  40.     0, 49,
  41.     1, 48,
  42.     1, 0,
  43.     238, 0
  44.     };
  45.  
  46. SHORT OGadget_Render1XYb[] =
  47.     {
  48.     1, 49,
  49.     239, 49,
  50.     239, 0,
  51.     238, 1,
  52.     238, 49
  53.     };
  54.  
  55. struct Border OGadget_Render1Ub =
  56.     {
  57.     0, 0,
  58.     2, 0, JAM1,
  59.     5,
  60.     OGadget_Render1XYb,
  61.     NULL
  62.     };
  63.  
  64. struct Border OGadget_Render1Ua =
  65.     {
  66.     0, 0,
  67.     1, 0, JAM1,
  68.     5,
  69.     OGadget_Render1XYa,
  70.     &OGadget_Render1Ub
  71.     };
  72.  
  73. struct Border OGadget_Render1Sb =
  74.     {
  75.     0, 0,
  76.     1, 0, JAM1,
  77.     5,
  78.     OGadget_Render1XYb,
  79.     NULL
  80.     };
  81.  
  82. struct Border OGadget_Render1Sa =
  83.     {
  84.     0, 0,
  85.     2, 0, JAM1,
  86.     5,
  87.     OGadget_Render1XYa,
  88.     &OGadget_Render1Sb
  89.     };
  90.  
  91. /* Option Gadget Render2 */
  92.  
  93. SHORT OGadget_Render2XYa[] =
  94.     {
  95.     0, 0,
  96.     0, 10,
  97.     1, 10,
  98.     1, 0,
  99.     24, 0
  100.     };
  101.  
  102. SHORT OGadget_Render2XYb[] =
  103.     {
  104.     1, 10,
  105.     25, 10,
  106.     25, 0,
  107.     24, 1,
  108.     24, 10
  109.     };
  110.  
  111. struct Border OGadget_Render2Ub =
  112.     {
  113.     0, 0,
  114.     2, 0, JAM1,
  115.     5,
  116.     OGadget_Render2XYb,
  117.     NULL
  118.     };
  119.  
  120. struct Border OGadget_Render2Ua =
  121.     {
  122.     0, 0,
  123.     1, 0, JAM1,
  124.     5,
  125.     OGadget_Render2XYa,
  126.     &OGadget_Render2Ub
  127.     };
  128.  
  129. struct Border OGadget_Render2Sb =
  130.     {
  131.     0, 0,
  132.     1, 0, JAM1,
  133.     5,
  134.     OGadget_Render2XYb,
  135.     NULL
  136.     };
  137.  
  138. struct Border OGadget_Render2Sa =
  139.     {
  140.     0, 0,
  141.     2, 0, JAM1,
  142.     5,
  143.     OGadget_Render2XYa,
  144.     &OGadget_Render2Sb
  145.     };
  146.  
  147. /* Option Gadget 7 */
  148.  
  149. struct IntuiText OGadget7_Text =
  150.     {
  151.     1, 0, JAM1,
  152.     5, 2,
  153.     &fontdef,
  154.     "<-",
  155.     NULL
  156.     };
  157.  
  158. struct Gadget OGadget7 =
  159.     {
  160.     NULL,
  161.     376, 82, 26, 11,
  162.     GADGHIMAGE,
  163.     GADGIMMEDIATE | RELVERIFY,
  164.     BOOLGADGET,
  165.     &OGadget_Render2Ua,
  166.     &OGadget_Render2Sa,
  167.     &OGadget7_Text,
  168.     0,
  169.     0,
  170.     6,
  171.     NULL
  172.     };
  173.  
  174. /* Option Gadget 6 */
  175.  
  176. struct IntuiText OGadget6_Text =
  177.     {
  178.     1, 0, JAM1,
  179.     5, 2,
  180.     &fontdef,
  181.     "->",
  182.     NULL
  183.     };
  184.  
  185. struct Gadget OGadget6 =
  186.     {
  187.     &OGadget7,
  188.     158, 94, 26, 11,
  189.     GADGHIMAGE,
  190.     GADGIMMEDIATE | RELVERIFY,
  191.     BOOLGADGET,
  192.     &OGadget_Render2Ua,
  193.     &OGadget_Render2Sa,
  194.     &OGadget6_Text,
  195.     0,
  196.     0,
  197.     5,
  198.     NULL
  199.     };
  200.  
  201. /* Option Gadget 5 */
  202.  
  203. struct IntuiText OGadget5_Text =
  204.     {
  205.     1, 0, JAM1,
  206.     5, 2,
  207.     &fontdef,
  208.     "<-",
  209.     NULL
  210.     };
  211.  
  212. struct Gadget OGadget5 =
  213.     {
  214.     &OGadget6,
  215.     130, 94, 26, 11,
  216.     GADGHIMAGE,
  217.     GADGIMMEDIATE | RELVERIFY,
  218.     BOOLGADGET,
  219.     &OGadget_Render2Ua,
  220.     &OGadget_Render2Sa,
  221.     &OGadget5_Text,
  222.     0,
  223.     0,
  224.     4,
  225.     NULL
  226.     };
  227.  
  228. /* Option Gadget 4 */
  229.  
  230. struct IntuiText OGadget4_Text =
  231.     {
  232.     1, 0, JAM1,
  233.     5, 2,
  234.     &fontdef,
  235.     "->",
  236.     NULL
  237.     };
  238.  
  239. struct Gadget OGadget4 =
  240.     {
  241.     &OGadget5,
  242.     158, 82, 26, 11,
  243.     GADGHIMAGE,
  244.     GADGIMMEDIATE | RELVERIFY,
  245.     BOOLGADGET,
  246.     &OGadget_Render2Ua,
  247.     &OGadget_Render2Sa,
  248.     &OGadget4_Text,
  249.     0,
  250.     0,
  251.     3,
  252.     NULL
  253.     };
  254.  
  255. /* Option Gadget 3 */
  256.  
  257. struct IntuiText OGadget3_Text =
  258.     {
  259.     1, 0, JAM1,
  260.     5, 2,
  261.     &fontdef,
  262.     "<-",
  263.     NULL
  264.     };
  265.  
  266. struct Gadget OGadget3 =
  267.     {
  268.     &OGadget4,
  269.     130, 82, 26, 11,
  270.     GADGHIMAGE,
  271.     GADGIMMEDIATE | RELVERIFY,
  272.     BOOLGADGET,
  273.     &OGadget_Render2Ua,
  274.     &OGadget_Render2Sa,
  275.     &OGadget3_Text,
  276.     0,
  277.     0,
  278.     2,
  279.     NULL
  280.     };
  281.  
  282. /* Option Gadget 2 */
  283.  
  284. struct IntuiText OGadget2_Text =
  285.     {
  286.     1, 0, JAM1,
  287.     100, 21,
  288.     &fontdef,
  289.     "Start",
  290.     NULL
  291.     };
  292.  
  293. struct Gadget OGadget2 =
  294.     {
  295.     &OGadget3,
  296.     280, 20, 240, 50,
  297.     GADGHIMAGE,
  298.     RELVERIFY,
  299.     BOOLGADGET,
  300.     &OGadget_Render1Ua,
  301.     &OGadget_Render1Sa,
  302.     &OGadget2_Text,
  303.     0,
  304.     0,
  305.     1,
  306.     NULL
  307.     };
  308.  
  309. /* Option Gadget 1 */
  310.  
  311. struct IntuiText OGadget1_Text =
  312.     {
  313.     1, 0, JAM1,
  314.     100, 21,
  315.     &fontdef,
  316.     "About",
  317.     NULL
  318.     };
  319.  
  320. struct Gadget OGadget1 =
  321.     {
  322.     &OGadget2,
  323.     20, 20, 240, 50,
  324.     GADGHIMAGE,
  325.     RELVERIFY,
  326.     BOOLGADGET,
  327.     &OGadget_Render1Ua,
  328.     &OGadget_Render1Sa,
  329.     &OGadget1_Text,
  330.     0,
  331.     0,
  332.     0,
  333.     NULL
  334.     };
  335.  
  336. /* window def */
  337.  
  338. struct NewWindow nw =
  339.     {
  340.     50, 25, 640-100, 200-50,
  341.     0, 1,
  342.     GADGETUP | GADGETDOWN | RAWKEY | CLOSEWINDOW | MOUSEBUTTONS,
  343.     WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH |
  344.     REPORTMOUSE | NOCAREREFRESH | RMBTRAP | ACTIVATE,
  345.     NULL,
  346.     NULL,
  347.     "Ancient Egypt V1.0    © 1992 by Paradise Soft   FREEWARE",
  348.     NULL,
  349.     NULL,
  350.     0, 0, 0, 0,
  351.     WBENCHSCREEN
  352.     };
  353.  
  354. struct Window *window;
  355. struct RastPort *rp;
  356.  
  357. /* game data */
  358.  
  359. struct Player
  360.     {
  361.     SHORT x, y;
  362.     SHORT xwin, ywin;
  363.     SHORT Moves;
  364.     SHORT Chests;
  365.     SHORT xoff;
  366.     UBYTE mask[100][100];
  367.     };
  368.  
  369. struct Player Player1;
  370. struct Player Player2;
  371.  
  372. UBYTE world[100][100];
  373. SHORT worldx = 50;
  374. SHORT worldy = 50;
  375.  
  376. BOOL GameMode = TRUE;
  377.  
  378. /********************/
  379. /* main         */
  380. /********************/
  381.  
  382. int wbmain()
  383.     {
  384.     return(main());
  385.     }
  386.  
  387. int main()
  388.     {
  389.     srand(time(NULL));
  390.  
  391.     window = (struct Window *)OpenWindow(&nw);
  392.  
  393.     if ( window )
  394.         {
  395.         rp = window->RPort;
  396.  
  397.         BOOL loop = TRUE;
  398.         while ( loop )
  399.             {
  400.             switch ( SelectOption() )
  401.                 {
  402.                 case -1 :
  403.                     loop = FALSE;
  404.                     break;
  405.                 case 0 :
  406.                     loop = About();
  407.                     break;
  408.                 case 1 :
  409.                     loop = Game();
  410.                     break;
  411.                 }
  412.             }
  413.  
  414.         CloseWindow(window);
  415.         }
  416.     else
  417.         {
  418.         SHORT i;
  419.  
  420.         for ( i = 10 ; i ; i-- )
  421.             {
  422.             DisplayBeep(NULL);
  423.             Delay(2);
  424.             }
  425.         }
  426.     }
  427.  
  428. /********************/
  429. /* SelectOption()   */
  430. /********************/
  431.  
  432. SHORT SelectOption()
  433.     {
  434.     char Buffer[40];
  435.  
  436.     SetAPen(rp, 0);
  437.     RectFill(rp, 5, 11, 535, 147);
  438.  
  439.     SetAPen(rp, 1);
  440.     PrintAt(20, 80, "World Size :");
  441.     sprintf(Buffer, "Width  : %3u", worldx);
  442.     PrintAt(28, 90, Buffer);
  443.     sprintf(Buffer, "Height : %3u", worldy);
  444.     PrintAt(28, 102, Buffer);
  445.  
  446.     PrintAt(280, 80, "Game mode :");
  447.     if ( GameMode )
  448.         PrintAt(288, 90, "One Player");
  449.     else
  450.         PrintAt(288, 90, "Two Player");
  451.  
  452.     OGadget7.NextGadget = window->FirstGadget;
  453.     window->FirstGadget = &OGadget1;
  454.     RefreshGadgets(&OGadget1, window, NULL);
  455.  
  456.     while ( TRUE )
  457.         {
  458.         struct IntuiMessage *msg;
  459.  
  460.         Wait( 1 << window->UserPort->mp_SigBit );
  461.  
  462.         while ( msg = (struct IntuiMessage *)GetMsg(window->UserPort ))
  463.             {
  464.             ULONG class = msg->Class;
  465.             struct Gadget *iaddress = msg->IAddress;
  466.  
  467.             ReplyMsg(msg);
  468.  
  469.             switch ( class )
  470.                 {
  471.                 case CLOSEWINDOW :
  472.                     return(-1);
  473.                 case GADGETUP :
  474.                     switch ( iaddress->GadgetID )
  475.                     {
  476.                         case 0 :
  477.                         return(0);
  478.                         case 1 :
  479.                         return(1);
  480.                     }
  481.                     break;
  482.                 case GADGETDOWN :
  483.                     switch ( iaddress->GadgetID )
  484.                     {
  485.                         case 2 :
  486.                         while ( (worldx > 20) && (OGadget3.Flags & SELECTED) )
  487.                             {
  488.                             worldx--;
  489.                             SetAPen(rp, 1);
  490.                             sprintf(Buffer, "Width  : %3u", worldx);
  491.                             PrintAt(28, 90, Buffer);
  492.                             Delay(2);
  493.                             }
  494.                         break;
  495.                         case 3 :
  496.                         while ( (worldx < 100) && (OGadget4.Flags & SELECTED) )
  497.                             {
  498.                             worldx++;
  499.                             SetAPen(rp, 1);
  500.                             sprintf(Buffer, "Width  : %3u", worldx);
  501.                             PrintAt(28, 90, Buffer);
  502.                             Delay(2);
  503.                             }
  504.                         break;
  505.                         case 4 :
  506.                         while ( (worldy > 20) && (OGadget5.Flags & SELECTED) )
  507.                             {
  508.                             worldy--;
  509.                             SetAPen(rp, 1);
  510.                             sprintf(Buffer, "Height : %3u", worldy);
  511.                             PrintAt(28, 102, Buffer);
  512.                             Delay(2);
  513.                             }
  514.                         break;
  515.                         case 5 :
  516.                         while ( (worldy < 100) && (OGadget6.Flags & SELECTED) )
  517.                             {
  518.                             worldy++;
  519.                             SetAPen(rp, 1);
  520.                             sprintf(Buffer, "Height : %3u", worldy);
  521.                             PrintAt(28, 102, Buffer);
  522.                             Delay(2);
  523.                             }
  524.                         break;
  525.                         case 6 :
  526.                         GameMode = !GameMode;
  527.                         SetAPen(rp, 1);
  528.                         if ( GameMode )
  529.                             PrintAt(288, 90, "One Player");
  530.                         else
  531.                             PrintAt(288, 90, "Two Player");
  532.                         break;
  533.                     }
  534.                     break;
  535.                 }
  536.             }
  537.         }
  538.     }
  539.  
  540. /********************/
  541. /* About()          */
  542. /********************/
  543.  
  544. BOOL About()
  545.     {
  546.     struct IntuiMessage *msg;
  547.     BOOL loop = TRUE;
  548.  
  549.     window->FirstGadget = OGadget7.NextGadget;
  550.  
  551.     SetAPen(rp, 0);
  552.     RectFill(rp, 5, 11, 535, 147);
  553.  
  554.     DrawImage(rp, &AboutImage, 197, 20);
  555.  
  556.     SetAPen(rp, 1);
  557.     PrintAt(170, 80, "Coding & Graphics by Pink");
  558.     PrintAt(210, 90, "Idea by Romulus");
  559.  
  560.     SetAPen(rp, 3);
  561.     PrintAt(154, 110, "Read .doc for more information");
  562.  
  563.     while ( loop )
  564.         {
  565.         Wait( 1 << window->UserPort->mp_SigBit );
  566.  
  567.         while ( msg = (struct IntuiMessage *)GetMsg(window->UserPort ))
  568.             {
  569.             if ( (msg->Class == MOUSEBUTTONS) && (msg->Code == SELECTUP) )
  570.                 loop = FALSE;
  571.  
  572.             ReplyMsg(msg);
  573.             }
  574.         }
  575.  
  576.     return(TRUE);
  577.     }
  578.  
  579. /********************/
  580. /* Game()           */
  581. /********************/
  582.  
  583. BOOL Game()
  584.     {
  585.     BOOL loop = TRUE;
  586.  
  587.     window->FirstGadget = OGadget7.NextGadget;
  588.  
  589.     CreateWorld();
  590.  
  591.     /* init player */
  592.         {
  593.         Player1.x = (rand()%(worldx-1)) + 1;
  594.         Player1.y = (rand()%(worldy-1)) + 1;
  595.  
  596.         while ( world[Player1.x][Player1.y] != 0 )
  597.             {
  598.             Player1.x++;
  599.             if ( Player1.x >= worldx )
  600.                 {
  601.                 Player1.x = 1;
  602.                 Player1.y++;
  603.                 if ( Player1.y >= worldy )
  604.                     {
  605.                     Player1.x = 1;
  606.                     Player1.y = 1;
  607.                     }
  608.                 }
  609.             }
  610.  
  611.         Player1.xwin = Player1.x - 5;
  612.         if ( Player1.xwin < 0 )
  613.             Player1.xwin = 0;
  614.         else if ( Player1.xwin > worldx-12 )
  615.             Player1.xwin = worldx-12;
  616.  
  617.         Player1.ywin = Player1.y - 5;
  618.         if ( Player1.ywin < 0 )
  619.             Player1.ywin = 0;
  620.         else if ( Player1.ywin > worldy-11 )
  621.             Player1.ywin = worldy-11;
  622.  
  623.         Player1.Moves = 0;
  624.         Player1.Chests = 0;
  625.         Player1.xoff = 20;
  626.  
  627.         clrmem(Player1.mask, 100*100);
  628.  
  629.         Player2.x = (rand()%(worldx-1)) + 1;
  630.         Player2.y = (rand()%(worldy-1)) + 1;
  631.  
  632.         while ( world[Player2.x][Player2.y] != 0 )
  633.             {
  634.             Player2.x++;
  635.             if ( Player2.x >= worldx )
  636.                 {
  637.                 Player2.x = 1;
  638.                 Player2.y++;
  639.                 if ( Player2.y >= worldy )
  640.                     {
  641.                     Player2.x = 1;
  642.                     Player2.y = 1;
  643.                     }
  644.                 }
  645.             }
  646.  
  647.  
  648.         Player2.xwin = Player2.x - 5;
  649.         if ( Player2.xwin < 0 )
  650.             Player2.xwin = 0;
  651.         else if ( Player2.xwin > worldx-12 )
  652.             Player2.xwin = worldx-12;
  653.  
  654.         Player2.ywin = Player2.y - 5;
  655.         if ( Player2.ywin < 0 )
  656.             Player2.ywin = 0;
  657.         else if ( Player2.ywin > worldy-11 )
  658.             Player2.ywin = worldy-11;
  659.  
  660.         Player2.Moves = 0;
  661.         Player2.Chests = 0;
  662.         Player2.xoff = 280;
  663.  
  664.         clrmem(Player2.mask, 100*100);
  665.         }
  666.  
  667.     /* init screen */
  668.         {
  669.         SHORT x, y;
  670.  
  671.         SetAPen(rp, 0);
  672.         RectFill(rp, 5, 11, 535, 147);
  673.  
  674.         SetAPen(rp, 3);
  675.         RectFill(rp, 20, 30, 259, 139);
  676.  
  677.         for ( x = 0 ; x < 12 ; x++ )
  678.             for ( y = 0 ; y < 11 ; y++ )
  679.             PutField(&Player1, x+Player1.xwin, y+Player1.ywin);
  680.  
  681.         SetAPen(rp, 3);
  682.         RectFill(rp, 280, 30, 499, 139);
  683.  
  684.         for ( x = 0 ; x < 12 ; x++ )
  685.             for ( y = 0 ; y < 11 ; y++ )
  686.             PutField(&Player2, x+Player2.xwin, y+Player2.ywin);
  687.  
  688.         SetAPen(rp, 1);
  689.         PrintAt(20, 25, "Moves :   0  Chests : 0");
  690.         PrintAt(280, 25, "Moves :   0  Chests : 0");
  691.  
  692.         ChangePos(&Player1);
  693.         ChangePos(&Player2);
  694.         }
  695.  
  696.     while ( loop )
  697.         {
  698.         struct IntuiMessage *msg;
  699.  
  700.         Wait(1 << window->UserPort->mp_SigBit);
  701.  
  702.         while ( msg = (struct IntuiMessage *)GetMsg(window->UserPort) )
  703.             {
  704.             ULONG class = msg->Class;
  705.             USHORT code = msg->Code;
  706.             struct Gadget *iaddress = msg->IAddress;
  707.             SHORT mousex = msg->MouseX;
  708.             SHORT mousey = msg->MouseY;
  709.  
  710.             ReplyMsg(msg);
  711.  
  712.             switch ( class )
  713.                 {
  714.                 case CLOSEWINDOW :
  715.                     loop = FALSE;
  716.                 case RAWKEY :
  717.                     switch ( code )
  718.                     {
  719.                         case 0x11 :
  720.                         loop = DoPlayer(&Player1, 0);
  721.                         break;
  722.                         case 0x31 :
  723.                         loop = DoPlayer(&Player1, 1);
  724.                         break;
  725.                         case 0x20 :
  726.                         loop = DoPlayer(&Player1, 2);
  727.                         break;
  728.                         case 0x21 :
  729.                         loop = DoPlayer(&Player1, 3);
  730.                         break;
  731.                         case 0x3E :
  732.                         if ( !GameMode )
  733.                             loop = DoPlayer(&Player2, 0);
  734.                         break;
  735.                         case 0x1E :
  736.                         if ( !GameMode )
  737.                             loop = DoPlayer(&Player2, 1);
  738.                         break;
  739.                         case 0x2D :
  740.                         if ( !GameMode )
  741.                             loop = DoPlayer(&Player2, 2);
  742.                         break;
  743.                         case 0x2F :
  744.                         if ( !GameMode )
  745.                             loop = DoPlayer(&Player2, 3);
  746.                         break;
  747.                     }
  748.  
  749.                     break;
  750.                 }
  751.             }
  752.         }
  753.  
  754.     /* end message */
  755.         {
  756.         SetAPen(rp, 0);
  757.         RectFill(rp, 5, 11, 535, 147);
  758.  
  759.         if ( Player1.Chests == 3 )
  760.             {
  761.             SetAPen(rp, 1);
  762.             PrintAt(218, 80, "Player 1 wins");
  763.             }
  764.         else if ( Player2.Chests == 3 )
  765.             {
  766.             SetAPen(rp, 1);
  767.             PrintAt(218, 80, "Player 2 wins");
  768.             }
  769.         else
  770.             {
  771.             SetAPen(rp, 1);
  772.             PrintAt(214, 80, "No Player wins");
  773.             }
  774.  
  775.         struct IntuiMessage *msg;
  776.         BOOL loop = TRUE;
  777.  
  778.         while ( loop )
  779.             {
  780.             Wait( 1 << window->UserPort->mp_SigBit );
  781.  
  782.             while ( msg = (struct IntuiMessage *)GetMsg(window->UserPort ))
  783.                 {
  784.                 if ( (msg->Class == MOUSEBUTTONS) && (msg->Code == SELECTUP) )
  785.                     loop = FALSE;
  786.  
  787.                 ReplyMsg(msg);
  788.                 }
  789.             }
  790.         }
  791.  
  792.     return(TRUE);
  793.     }
  794.  
  795. /********************/
  796. /* DoPlayer()       */
  797. /********************/
  798.  
  799. void ChangePos(__A0 struct Player *p)
  800.     {
  801.     SHORT xs=p->x-p->xwin, ys=p->y-p->ywin;
  802.     SHORT x=p->x, y=p->y;
  803.  
  804.     p->mask[x+1][y-1] = TRUE; PutField(p, x+1, y-1);
  805.     p->mask[x]  [y-1] = TRUE; PutField(p, x,   y-1);
  806.     p->mask[x-1][y-1] = TRUE; PutField(p, x-1, y-1);
  807.     p->mask[x+1][y]   = TRUE; PutField(p, x+1, y);
  808.     p->mask[x]  [y]   = TRUE; DrawImage(rp, &ManImage, xs*20+p->xoff, ys*10+30);
  809.     p->mask[x-1][y]   = TRUE; PutField(p, x-1, y);
  810.     p->mask[x+1][y+1] = TRUE; PutField(p, x+1, y+1);
  811.     p->mask[x]  [y+1] = TRUE; PutField(p, x,   y+1);
  812.     p->mask[x-1][y+1] = TRUE; PutField(p, x-1, y+1);
  813.     }
  814.  
  815. BOOL DoPlayer(__A0 struct Player *p, __D0 UBYTE dir)
  816.     {
  817.     char Buffer[40];
  818.  
  819.     SetAPen(rp, 1);
  820.     sprintf(Buffer, "Moves : %3u  Chests : %u", p->Moves, p->Chests);
  821.     PrintAt(p->xoff, 25, Buffer);
  822.  
  823.     ChangePos(p);
  824.  
  825.     switch ( dir )
  826.         {
  827.         case 0 :
  828.             switch ( world[p->x][p->y-1] )
  829.             {
  830.                 case 3 :
  831.                 p->Chests++;
  832.                 if ( p->Chests == 3 )
  833.                     return(FALSE);
  834.                 world[p->x][p->y-1] = 0;
  835.                 case 0 :
  836.                 case 2 :
  837.                 p->y--;
  838.                 p->Moves++;
  839.  
  840.                 if ( (p->ywin > 1) && (p->y < p->ywin + 3) )
  841.                     {
  842.                     SHORT i;
  843.  
  844.                     ScrollRaster(rp, 0, -10, p->xoff, 30, p->xoff+239, 139);
  845.  
  846.                     p->ywin--;
  847.                     for ( i = 0 ; i < 12 ; i++ )
  848.                         PutField(p, i+p->xwin, p->ywin);
  849.                     }
  850.                 ChangePos(p);
  851.                 break;
  852.                 case 1 :
  853.                 DisplayBeep(NULL);
  854.                 break;
  855.             }
  856.             break;
  857.         case 1 :
  858.             switch ( world[p->x][p->y+1] )
  859.             {
  860.                 case 3 :
  861.                 p->Chests++;
  862.                 if ( p->Chests == 3 )
  863.                     return(FALSE);
  864.                 world[p->x][p->y+1] = 0;
  865.                 case 0 :
  866.                 case 2 :
  867.                 p->y++;
  868.                 p->Moves++;
  869.  
  870.                 if ( (p->ywin < worldy-11) && (p->y > p->ywin + 7) )
  871.                     {
  872.                     SHORT i;
  873.  
  874.                     ScrollRaster(rp, 0, 10, p->xoff, 30, p->xoff+239, 139);
  875.  
  876.                     p->ywin++;
  877.                     for ( i = 0 ; i < 12 ; i++ )
  878.                         PutField(p, p->xwin+i, p->ywin+10);
  879.                     }
  880.                 ChangePos(p);
  881.                 break;
  882.                 case 1 :
  883.                 DisplayBeep(NULL);
  884.                 break;
  885.             }
  886.             break;
  887.         case 2 :
  888.             switch ( world[p->x-1][p->y] )
  889.             {
  890.                 case 3 :
  891.                 p->Chests++;
  892.                 if ( p->Chests == 3 )
  893.                     return(FALSE);
  894.                 world[p->x-1][p->y] = 0;
  895.                 case 0 :
  896.                 case 2 :
  897.                 p->x--;
  898.                 p->Moves++;
  899.  
  900.                 if ( (p->xwin > 1) && (p->x < p->xwin + 3) )
  901.                     {
  902.                     SHORT i;
  903.  
  904.                     ScrollRaster(rp, -20, 0, p->xoff, 30, p->xoff+239, 139);
  905.  
  906.                     p->xwin--;
  907.                     for ( i = 0 ; i < 11 ; i++ )
  908.                         PutField(p, p->xwin, p->ywin+i);
  909.                     }
  910.                 ChangePos(p);
  911.                 break;
  912.                 case 1 :
  913.                 DisplayBeep(NULL);
  914.                 break;
  915.             }
  916.             break;
  917.         case 3 :
  918.             switch ( world[p->x+1][p->y] )
  919.             {
  920.                 case 3 :
  921.                 p->Chests++;
  922.                 if ( p->Chests == 3 )
  923.                     return(FALSE);
  924.                 world[p->x+1][p->y] = 0;
  925.                 case 0 :
  926.                 case 2 :
  927.                 p->x++;
  928.                 p->Moves++;
  929.  
  930.                 if ( (p->xwin < worldx-12) && (p->x > p->xwin + 8) )
  931.                     {
  932.                     SHORT i;
  933.  
  934.                     ScrollRaster(rp, 20, 0, p->xoff, 30, p->xoff+239, 139);
  935.  
  936.                     p->xwin++;
  937.                     for ( i = 0 ; i < 11 ; i++ )
  938.                         PutField(p, p->xwin+11, p->ywin+i);
  939.                     }
  940.                 ChangePos(p);
  941.                 break;
  942.                 case 1 :
  943.                 DisplayBeep(NULL);
  944.                 break;
  945.             }
  946.             break;
  947.         }
  948.  
  949.     return(TRUE);
  950.     }
  951.  
  952. /********************/
  953. /* CreateWorld()    */
  954. /********************/
  955.  
  956. void Set(__D0 SHORT x, __D1 SHORT y, __D2 SHORT c)
  957.     {
  958.     world[x][y] = c;
  959.     }
  960.  
  961. void CreateWay(__D0 SHORT x, __D1 SHORT y, __D2 SHORT d)
  962.     {
  963.     BOOL c = TRUE;
  964.  
  965.     while ( c )
  966.         {
  967.         switch ( d )
  968.             {
  969.             case 0 :
  970.                 switch ( world[x][y-1] )
  971.                 {
  972.                     case 0 :
  973.                     case 1 :
  974.                     y--;
  975.                     Set(x, y, 0);
  976.                     break;
  977.                     case 2 :
  978.                     case 3 :
  979.                     case 4 :
  980.                     c = FALSE;
  981.                     break;
  982.                 }
  983.                 break;
  984.  
  985.             case 1 :
  986.                 switch ( world[x][y+1] )
  987.                 {
  988.                     case 0 :
  989.                     case 1 :
  990.                     y++;
  991.                     Set(x, y, 0);
  992.                     break;
  993.                     case 2 :
  994.                     case 3 :
  995.                     case 4 :
  996.                     c = FALSE;
  997.                     break;
  998.                 }
  999.                 break;
  1000.  
  1001.             case 2 :
  1002.                 switch ( world[x-1][y] )
  1003.                 {
  1004.                     case 0 :
  1005.                     case 1 :
  1006.                     x--;
  1007.                     Set(x, y, 0);
  1008.                     break;
  1009.                     case 2 :
  1010.                     case 3 :
  1011.                     case 4 :
  1012.                     c = FALSE;
  1013.                     break;
  1014.                 }
  1015.                 break;
  1016.  
  1017.             case 3 :
  1018.                 switch ( world[x+1][y] )
  1019.                 {
  1020.                     case 0 :
  1021.                     case 1 :
  1022.                     x++;
  1023.                     Set(x, y, 0);
  1024.                     break;
  1025.                     case 2 :
  1026.                     case 3 :
  1027.                     case 4 :
  1028.                     c = FALSE;
  1029.                     break;
  1030.                 }
  1031.                 break;
  1032.             } /* switch */
  1033.  
  1034.         if ( (rand() & 15) == 0 )
  1035.             {
  1036.             if ( (rand() & 1) == 0 )
  1037.                 d += 2;
  1038.             else
  1039.                 d -= 2;
  1040.  
  1041.             if ( d < 0 )
  1042.                 d += 3;
  1043.             else if ( d > 3 )
  1044.                 d -= 3;
  1045.             }
  1046.         } /* for */
  1047.     }
  1048.  
  1049. void CreateWorld()
  1050.     {
  1051.     SHORT x, y;
  1052.     SHORT i;
  1053.  
  1054.     SetAPen(rp, 0);
  1055.     RectFill(rp, 5, 11, 535, 147);
  1056.  
  1057.     SetAPen(rp, 1);
  1058.     PrintAt(198, 80, "Creating Map...");
  1059.  
  1060.     for ( x = 0 ; x <= worldx ; x++ )
  1061.         {
  1062.         Set(x, 0, 4);
  1063.         Set(x, worldy, 4);
  1064.         }
  1065.  
  1066.     for ( y = 1 ; y < worldy ; y++ )
  1067.         {
  1068.         Set(0, y, 4);
  1069.         Set(worldx, y, 4);
  1070.         for ( x = 1 ; x < worldx ; x++ )
  1071.             Set(x, y, 1);
  1072.         }
  1073.  
  1074.     for ( i = worldx*worldy/400 ; i ; i-- )
  1075.         {
  1076.         SHORT xd = (rand() % (worldx-9)) + 3;
  1077.         SHORT yd = (rand() % (worldy-9)) + 3;
  1078.         SHORT xs = (rand() & 3) + 3 + xd;
  1079.         SHORT ys = (rand() & 3) + 3 + yd;
  1080.  
  1081.         if ( xs > worldx-2 )
  1082.             xs = worldx-2;
  1083.  
  1084.         if ( ys > worldy-2 )
  1085.             ys = worldy-2;
  1086.  
  1087.         for ( x = xd ; x < xs ; x++ )
  1088.             for ( y = yd ; y < ys ; y++ )
  1089.             Set(x, y, 3);
  1090.  
  1091.         x = xd + ( rand() % (xs-xd) );
  1092.         if ( rand() & 1 )
  1093.             {
  1094.             if ( world[x][yd - 1] == 1 )
  1095.                 {
  1096.                 Set(x, yd - 1, 2);
  1097.                 CreateWay(x, yd - 1, 0);
  1098.                 }
  1099.             }
  1100.         else
  1101.             {
  1102.             if ( world[x][ys] == 1 )
  1103.                 {
  1104.                 Set(x, ys, 2);
  1105.                 CreateWay(x, ys, 1);
  1106.                 }
  1107.             }
  1108.  
  1109.         y = yd + ( rand() % (ys-yd) );
  1110.         if ( rand() & 1 )
  1111.             {
  1112.             if ( world[xd - 1][y] == 1 )
  1113.                 {
  1114.                 Set(xd - 1, y, 2);
  1115.                 CreateWay(xd - 1, y, 2);
  1116.                 }
  1117.             }
  1118.         else
  1119.             {
  1120.             if ( world[xs][y] == 1 )
  1121.                 {
  1122.                 Set(xs, y, 2);
  1123.                 CreateWay(xs, y, 3);
  1124.                 }
  1125.             }
  1126.         }
  1127.  
  1128.     for ( x = 1 ; x < worldx ; x++ )
  1129.         for ( y = 1 ; y < worldy ; y++ )
  1130.         {
  1131.             if ( world[x][y] == 3 )
  1132.             Set(x, y, 0);
  1133.             else if ( world[x][y] == 4 )
  1134.             Set(x, y, 1);
  1135.         }
  1136.  
  1137.     for ( i = 0 ; i < 5 ; i++ )
  1138.         {
  1139.         x = (rand() % (worldx-1)) + 1;
  1140.         y = (rand() % (worldy-1)) + 1;
  1141.  
  1142.         while ( world[x][y] != 0 )
  1143.             {
  1144.             x++;
  1145.             if ( x >= worldx )
  1146.                 {
  1147.                 x = 1;
  1148.                 y++;
  1149.                 if ( y >= worldy )
  1150.                     {
  1151.                     x = 1;
  1152.                     y = 1;
  1153.                     }
  1154.                 }
  1155.             }
  1156.  
  1157.         Set(x, y, 3);
  1158.         }
  1159.     }
  1160.  
  1161. /********************/
  1162. /* PutField()       */
  1163. /********************/
  1164.  
  1165. void PutField(__A0 struct Player *p, __D0 SHORT x, __D1 SHORT y)
  1166.     {
  1167.     SHORT xs = (x - p->xwin) * 20 + p->xoff;
  1168.     SHORT ys = (y - p->ywin) * 10 + 30;
  1169.  
  1170.     if ( p->mask[x][y] )
  1171.         if ( ((Player1.x == x) && (Player1.y == y)) || ((Player2.x == x) && (Player2.y == y)) )
  1172.         {
  1173.             DrawImage(rp, &ManImage, xs, ys);
  1174.         }
  1175.         else
  1176.         switch ( world[x][y] )
  1177.             {
  1178.             case 0 :
  1179.                 DrawImage(rp, &FloorImage, xs, ys);
  1180.                 break;
  1181.             case 1 :
  1182.                 DrawImage(rp, &WallImage, xs, ys);
  1183.                 break;
  1184.             case 2 :
  1185.                 DrawImage(rp, &DoorImage, xs, ys);
  1186.                 break;
  1187.             case 3 :
  1188.                 DrawImage(rp, &ChestImage, xs, ys);
  1189.                 break;
  1190.             }
  1191.     else
  1192.         DrawImage(rp, &UnknownImage, xs, ys);
  1193.     }
  1194.  
  1195. /********************/
  1196. /* PrintAt()        */
  1197. /********************/
  1198.  
  1199. void PrintAt(__D0 SHORT x, __D1 SHORT y, __A0 char *t)
  1200.     {
  1201.     Move(rp, x, y);
  1202.     Text(rp, t, strlen(t));
  1203.     }
  1204.  
  1205.